<?php

define('PUN_ROOT', './');
require 'config.php';
require PUN_ROOT.'include/functions.php';
require PUN_ROOT.'include/utf8/utf8.php';
require PUN_ROOT.'include/dblayer/common_db.php';
//require PUN_ROOT.'include/common.php';

if (isset($_POST['form_sent']))
{
	$realname = pun_trim($_POST['realname']);
	$username = pun_trim($_POST['username']);
	$W_country = pun_trim($_POST['W_country']);
	$W_state = pun_trim($_POST['W_state']);
	$W_city = pun_trim($_POST['W_city']);
	$W_town = pun_trim($_POST['W_town']);
	$work = pun_trim($_POST['work']);
	$educationleve = pun_trim($_POST['educationleve']);
	$email = pun_trim($_POST['email']);
	$imid = pun_trim($_POST['imid']);
	$b_year = isset($_POST['b_year']) ? intval($_POST['b_year']) : 0;
	$b_month = isset($_POST['b_month']) ? intval($_POST['b_month']) : 0;
	$b_day = isset($_POST['b_day']) ? intval($_POST['b_day']) : 0;
	$s_year = isset($_POST['s_year']) ? intval($_POST['s_year']) : 0;
	$s_month = isset($_POST['s_month']) ? intval($_POST['s_month']) : 0;
	$s_day = isset($_POST['s_day']) ? intval($_POST['s_day']) : 0;
	$s_hour = isset($_POST['s_hour']) ? intval($_POST['s_hour']) : 0;
	$time_seg = pun_trim($_POST['time_seg']);
	$s_country = pun_trim($_POST['s_country']);
	$s_state = pun_trim($_POST['s_state']);
	$s_city = pun_trim($_POST['s_city']);
	$s_town = pun_trim($_POST['s_town']);
	$s_time_day = pun_trim($_POST['s_time_day']);
	$s_time_h = pun_trim($_POST['s_time_h']);
	$s_time_min = pun_trim($_POST['s_time_min']);
	$temp = pun_trim($_POST['temp']);
	$weather = pun_trim($_POST['weather']);
	$wind = pun_trim($_POST['wind']);
	$is_thunder = pun_trim($_POST['is_thunder']);
	$climate = pun_trim($_POST['climate']);
	$topography = pun_trim($_POST['topography']);
	$vegetation = pun_trim($_POST['vegetation']);
	$position = pun_trim($_POST['position']);
	$lunar = pun_trim($_POST['lunar']);
	$option_num = pun_trim($_POST['option_num']);
	$distance = pun_trim($_POST['distance']);
	$uma_size = pun_trim($_POST['uma_size']);
	$uma_form = pun_trim($_POST['uma_form']);
	$undirect = isset($_POST['undirect']) ? intval($_POST['undirect']) : 0;
	$appear = isset($_POST['appear']) ? intval($_POST['appear']) : 0;
	$uma_appear = pun_trim($_POST['uma_appear']);
	$disappear = isset($_POST['disappear']) ? intval($_POST['disappear']) : 0;
	$uma_disappear = pun_trim($_POST['uma_disappear']);
	$witness = isset($_POST['witness']) ? intval($_POST['witness']) : 0;
	$person_num = pun_trim($_POST['person_num']);
	$move_style = pun_trim($_POST['move_style']);
	$uma_color = pun_trim($_POST['uma_color']);
	$uma_sound = isset($_POST['uma_sound']) ? intval($_POST['uma_sound']) : 0;
	$uma_voice = pun_trim($_POST['uma_voice']);
	$smell = isset($_POST['smell']) ? intval($_POST['smell']) : 0;
	$uma_smell = pun_trim($_POST['uma_smell']);
	$option_cc = isset($_POST['option_cc']) ? intval($_POST['option_cc']) : 0;
	$option_cs = isset($_POST['option_cs']) ? intval($_POST['option_cs']) : 0;
	$option_tf = isset($_POST['option_tf']) ? intval($_POST['option_tf']) : 0;
	$uma_marks = isset($_POST['uma_marks']) ? $_POST['uma_marks'] : array();
	$v_form = pun_trim($_POST['v_form']);
	$skin_type = pun_trim($_POST['skin_type']);
	$skin_matter = pun_trim($_POST['skin_matter']);
	$animal_type = pun_trim($_POST['animal_type']);
	$other_animal = isset($_POST['other_animal']) ? intval($_POST['other_animal']) : 0;
	$vehicle = isset($_POST['vehicle']) ? intval($_POST['vehicle']) : 0;
	$sickness = isset($_POST['sickness']) ? $_POST['sickness'] : array();
	$mentality = isset($_POST['mentality']) ? $_POST['mentality'] : array();
	$bases = isset($_POST['bases']) ? intval($_POST['bases']) : 0;
	$what_obj = pun_trim($_POST['what_obj']);
	$evidence = isset($_POST['evidence']) ? intval($_POST['evidence']) : 0;
	$filelink = pun_trim($_POST['filelink']);
	$invested = isset($_POST['invested']) ? intval($_POST['invested']) : 0;
	$warned = isset($_POST['warned']) ? intval($_POST['warned']) : 0;
	$acc_sec = isset($_POST['acc_sec']) ? intval($_POST['acc_sec']) : 0;


	$uma_marks_str = implode("，", $uma_marks);
	$sickness_str = implode("，", $sickness);
	$mentality_str = implode("，", $mentality);

	$now = time();

	$sql = 'INSERT INTO '.$db_prefix.'reports (poster_ip, posttime, realname, username, W_country, W_state, W_city, W_town, work, educationleve, email, imid, b_year, b_month, b_day, s_year, s_month, s_day, s_hour, time_seg, s_country, s_state, s_city, s_town, s_time_day, s_time_h, s_time_min, temp, weather, wind, is_thunder, climate, topography, vegetation, position, lunar, option_num, distance, uma_size, uma_form, undirect, appear, uma_appear, disappear, uma_disappear, witness, person_num, move_style, uma_color, uma_sound, uma_voice, smell, uma_smell, option_cc, option_cs, option_tf, uma_marks, v_form, skin_type, skin_matter, animal_type, other_animal, vehicle, sickness, mentality, bases, what_obj, evidence, filelink, invested, warned, acc_sec) VALUES(\''.get_remote_address().'\', '.$now.', \''.$db->escape($realname).'\', \''.$db->escape($username).'\', \''.$db->escape($W_country).'\', \''.$db->escape($W_state).'\', \''.$db->escape($W_city).'\', \''.$db->escape($W_town).'\', \''.$db->escape($work).'\', \''.$db->escape($educationleve).'\', \''.$db->escape($email).'\', \''.$db->escape($imid).'\', '.$b_year.', '.$b_month.', '.$b_day.', '.$s_year.', '.$s_month.', '.$s_day.', '.$s_hour.', \''.$db->escape($time_seg).'\', \''.$db->escape($s_country).'\', \''.$db->escape($s_state).'\', \''.$db->escape($s_city).'\', \''.$db->escape($s_town).'\', \''.$db->escape($s_time_day).'\', \''.$db->escape($s_time_h).'\', \''.$db->escape($s_time_min).'\', \''.$db->escape($temp).'\', \''.$db->escape($weather).'\', \''.$db->escape($wind).'\', \''.$db->escape($is_thunder).'\', \''.$db->escape($climate).'\', \''.$db->escape($topography).'\', \''.$db->escape($vegetation).'\', \''.$db->escape($position).'\', \''.$db->escape($lunar).'\', \''.$db->escape($option_num).'\', \''.$db->escape($distance).'\', \''.$db->escape($uma_size).'\', \''.$db->escape($uma_form).'\', '.$undirect.', '.$appear.', \''.$db->escape($uma_appear).'\', '.$disappear.', \''.$db->escape($uma_disappear).'\', '.$witness.', \''.$db->escape($person_num).'\', \''.$db->escape($move_style).'\', \''.$db->escape($uma_color).'\', '.$uma_sound.', \''.$db->escape($uma_voice).'\', '.$smell.', \''.$db->escape($uma_smell).'\', '.$option_cc.', '.$option_cs.', '.$option_tf.', \''.$db->escape($uma_marks_str).'\', \''.$db->escape($v_form).'\', \''.$db->escape($skin_type).'\', \''.$db->escape($skin_matter).'\', \''.$db->escape($animal_type).'\', '.$other_animal.', '.$vehicle.', \''.$db->escape($sickness_str).'\', \''.$db->escape($mentality_str).'\', '.$bases.', \''.$db->escape($what_obj).'\', '.$evidence.', \''.$db->escape($filelink).'\', '.$invested.', '.$warned.', '.$acc_sec.')';
	$db->query($sql) or error('Unable to insert to table '.$db_prefix.'reports. Please check your settings and try again.',  __FILE__, __LINE__, $db->error());

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>成功</title>
<style type="text/css">
<!--
BODY {MARGIN: 10% 20% auto 20%; font: 14px Verdana, Arial, Helvetica, sans-serif}
#messagebox {BORDER: 1px solid #0066B9}
H2 {MARGIN: 0; COLOR: #FFFFFF; BACKGROUND-COLOR: #0066B9; FONT-SIZE: 1.1em; PADDING: 5px 4px}
#messagebox DIV {PADDING: 6px 5px; BACKGROUND-COLOR: #F1F1F1}
-->
</style>
</head>
<body>

<div id="messagebox">
	<h2>成功</h2>
	<div>
		<strong>您提交的报告已收到，谢谢！</strong>
		<br/>
		<br/>
		<a href="http://yinglong.org">回到网站首页</a>
	</div>
</div>

</body>
</html>
<?php
}//end if
else
{
}
?>
